package com.learning.spring.ioc.property.editor.javabean;

import com.learning.spring.ioc.property.editor.entity.User;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;

/**
 * ClassName: UserBeanInfo
 * Description: 用户 User 对应的 BeanInfo 类，将属性编辑器和 User 的属性关联起来
 * Date: 2020/7/29 14:45 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class UserBeanInfo extends SimpleBeanInfo {
    @Override
    public PropertyDescriptor[] getPropertyDescriptors() {
        PropertyDescriptor propertyDescriptor = null;
        try {
            // 把属性与属性编辑器关联起来
            propertyDescriptor = new PropertyDescriptor("sex", User.class);
            // 设置属性编辑器
            propertyDescriptor.setPropertyEditorClass(UserSexEditor.class);
        } catch (IntrospectionException e) {
            e.printStackTrace();
        }

        return new PropertyDescriptor[]{propertyDescriptor};
    }
}